import http from "@/http";

export const userListApi = (params: IApiParams): RES<IUserListModel> =>
  http.get("/admin/list", { params });

export const changeUserStatueApi = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserApi = (params: List): RES<List> =>
  http.post("/admin/register", params);

//根据id查询用户信息
export const getUserByIdApi = (id: number): RES<List> =>
  http.get(`/admin/${id}`);

//编辑用户
export const updateUserApi = (params: List): RES<number> =>
  http.post(`/admin/update/${params.id}`, params);

//获取全部角色列表
export const getRoleListApi = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

//获取对应用户的角色
export const getUserRoleApi = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

//分配用户角色
export const updateUserRolesApi = (
  adminId: number,
  ids: number[]
): RES<number> =>
  http.post(`/admin/role/update?adminId=${adminId}&roleIds=${ids.join(",")}`);

//根据角色名称获取角色列表
export const getRoleByUserNameApi = (params: IApiParams): RES<IUserListModel> =>
  http.get("/role/list", { params });

//添加角色
export const addRoleApi = (role: IRoleModel): RES<any> =>
  http.post("/role/create", role);
//编辑角色
export const editRoleApi = (role: IRoleModel): RES<any> =>
  http.post(`/role/update/${role.id}`, role);
//通过id获取相应角色信息
export const getRoleByIdApi = (roleId: number): RES<any> =>
  http.get(`/role/listResource/${roleId}`);
//修改角色状态
export const changeRoleStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);
//获取所有角色
export const getAllRoleApi = (): RES<IRoleModel[]> => http.get("/role/listAll");

//获取角色资源
export const getRoleResourceApi = (roleId: number): RES<IResourceModel[]> =>
  http.get(`/role/listResource/${roleId}`);
//获取资源列表
export const getResourceListApi = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");
//查询所有后台资源分类
export const getResourceCategoryAllApi = (): RES<IResourceCategoryModel[]> =>
  http.get("/resourceCategory/listAll");
//给角色分配资源
export const allocResourceApi = (params: IAllocResourceParams): RES<any> =>
  http.post(
    `/role/allocResource?roleId=${
      params.roleId
    }&resourceIds=${params.resourceIds.join(",")}`
  );
//获取全部菜单列表
export const treeListApi = (): RES<ITreeMenu[]> => http.get("/menu/treeList");
